'use strict';
/**
 * @description 分页参数校验中间件
 * */
module.exports = () => {
  return async (ctx, next) => {
    const { pageIndex, pageSize } = ctx.params();
    const { createdAt } = ctx.queries;
    const intReg = /^[0-9]+$/;
    if (pageIndex === undefined || intReg.test(pageIndex) && (pageSize === undefined || intReg.test(pageSize)) && ((createdAt && createdAt instanceof Array && createdAt.length === 2) || createdAt === undefined)) {
      await next();
    } else {
      ctx.body = {
        status: 500,
        message: '参数错误',
      };
    }
  };
};
